package annotation;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @since Oct 16, 2017
 */
public class AnnotationTracker {
    @ParentAnnotation(id = 47, name = "trackAnnotation")
    public static void trackAnnotation(List<Integer> annos, Class<?> cl) {
        for (Method m : cl.getDeclaredMethods()) {
            ParentAnnotation parentAnnotation = m.getAnnotation(ParentAnnotation.class);
            if (parentAnnotation != null) {
                System.out.println("Found annotation: " + parentAnnotation.id() + " " + parentAnnotation.name());
                annos.remove(new Integer(parentAnnotation.id()));
            }
        }
        for (int i : annos) {
            System.out.println("Warning: missing annotation " + i);
        }
    }

    @ParentAnnotation(id = 2)
    public static void main(String[] args) {
        List<Integer> annos = new ArrayList<Integer>();
        Collections.addAll(annos, 47, 48, 49, 50);
        trackAnnotation(annos, AnnotationTracker.class);
    }
}
